package com.b3434.Processor;

import com.b3434.Utils.AESEncryptHelper;
import com.b3434.Utils.Base64Utils;
import org.apache.avro.generic.GenericRecord;

import java.util.List;

/**
 * Created by Lee on 2017/3/24 0024.
 */
public class EncryptProcessor extends Processor{
    Processor processor;
    public EncryptProcessor(Processor processor) {
        this.processor = processor;
        this.parameter = processor.parameter;

    }
    @Override
    public GenericRecord process(String originStr) {
        dataMap=processor.process(originStr);
        List<String> filedNameToEncrypt = parameter.getFiledNameEncryptedList();
        String key = parameter.getAESPriKey();
        for (String str : filedNameToEncrypt) {
                try {
                    if (dataMap.get(str)!=null)
                    dataMap.put( str,AESEncryptHelper.aesEncrypt((String) dataMap.get(str), key, "UTF-8"));
                } catch (Exception e) {
                    e.printStackTrace();
                }
        }
        return dataMap;
    }
}
